package com.yunxi.controller.sat;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.sat.pojo.SatMessVO;
import com.yunxi.sat.service.SatMessDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author
 * @since 2019-07-16
 */
@RestController
@RequestMapping("/admin/satmess")
@Api(tags = "sat:satmess", description = "消息接口")
public class SatMessController {
   private static final Logger logger = LoggerFactory.getLogger(SatMessController.class);

   @Autowired
   SatMessDubboService satMessDubboService;

   @GetMapping("/page")
   @ApiOperation(value = "查询分页")
   public ApiResult page(SatMessVO satMessVO, Integer pageNum, Integer pageSize,@CurrentUser LoginInfo loginInfo) throws Exception {
      satMessVO.setPartnerCode(loginInfo.getPartnerCode());
      satMessVO.setReceiveRoleCode(loginInfo.getRoleCode());
      return ResponseUtil.ok(satMessDubboService.findPageByVO(satMessVO, pageNum, pageSize,loginInfo));
   }

   @GetMapping("/list")
   @ApiOperation(value = "查询列表")
   public ApiResult list(SatMessVO satMessVO) throws Exception {
      return ResponseUtil.ok(satMessDubboService.listByVo(satMessVO));
   }

   @GetMapping("/load")
   @ApiOperation(value = "读取单个")
   public ApiResult load(SatMessVO satMessVO, @CurrentUser LoginInfo loginInfo) throws Exception {
      return ResponseUtil.ok(satMessDubboService.getById(satMessVO.getMessId()));
   }

   @PostMapping("/save")
   @ApiOperation(value = "保存信息")
   public ApiResult save(@RequestBody SatMessVO satMessVO, @CurrentUser LoginInfo loginInfo) throws Exception {
      satMessDubboService.saveOrUpdate(satMessVO);
      return ResponseUtil.ok("success");
   }

   @PostMapping("/del")
   @ApiOperation(value = "删除")
   public ApiResult del(@RequestBody List<SatMessVO> satMessVOList) throws Exception {
      satMessDubboService.removeByListVo(satMessVOList);
      return ResponseUtil.ok("success");
   }

}
